import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormArray, FormControl, ControlContainer, FormGroupName } from '@angular/forms';
import * as dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs.extend(customParseFormat);

@Component({
	selector: 'm-schedule',
	templateUrl: './schedule.component.html',
	styleUrls: ['./schedule.component.scss'],
})
export class ScheduleComponent implements OnInit {
	readonly weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];

	formGroup = new FormGroup({
		time: new FormControl(new Date()),
		weekdays: new FormArray(this.weeks.map(() => new FormControl(false))),
	});

	touched: () => void;
	@Input() required: boolean;
	constructor(private controlContainer: ControlContainer) {}

	ngOnInit() {
		if (this.controlContainer instanceof FormGroupName) {
			this.formGroup = this.controlContainer.control;
		}
	}
}
